#pragma once

#include <QtUi/ModelTest.hpp>

#include "GeneratedFiles/ui/ui_ProjectExplorer.h"

#include "State.hpp"
#include "Project.hpp"
#include "ProjectModel.hpp"




namespace Engine
{
	namespace Edit
	{
		class ProjectExplorer
			: public QWidget
		{
			Q_OBJECT

		public:

			/**
			 * This enumeration defines several predefined items that
			 * are always present in the project tree (unless no project is loaded).
			 */
			enum SpecialItem
			{
				Project,
				Scripts,
				UiDefinitions,
				Materials,
				Meshes,
			};



			ProjectExplorer(QWidget* parent);
			virtual ~ProjectExplorer();



			/**
			 * Sets the given project as the one to be displayed.
			 * When no project is passed, the view displays nothing.
			 */
			void setProject(Project::ptr project);

			void changeState(State::Type state);

		public slots:

			/**
			 * Ensures that the given item is visible in the project explorer.
			 */
			void ensureVisible(ProjectItem::ptr item);

			/**
			 * Selects the given item in the project explorer.
			 */
			void select(ProjectItem::ptr item, QItemSelectionModel::SelectionFlags flags);

			/**
			 * @returns the actual item from the project tree or null if there is no such item
			 */
			ProjectItem::ptr item(SpecialItem where) const;

		protected slots:

			void onContextMenuRequested(const QPoint& point);
			void onSelectionChanged(const QItemSelection& selected, const QItemSelection& unselected);
			//void onSelectionChanged();
			void onDoubleClicked(const QModelIndex& index);
			void removeSelectedItems();

		signals:

			/**
			 * This signal is emitted whenever an item is selected by the user.
			 */
			void selected(QList<ProjectItem::ptr> selected, QList<ProjectItem::ptr> unselected);
			//void selected(ProjectItem::ptr selected);

			/**
			 * This signal is emitted whenever an item is double clicked by the user.
			 */
			void doubleClicked(ProjectItem::ptr item);

		private:

			/**
			 * @returns a list of ProjectItems for the given item selection.
			 */
			QList<ProjectItem::ptr> items(const QItemSelection& selection) const;

		private:

			::Ui::ProjectExplorer   ui;

			State::Type             m_state;
			Project::ptr            m_project;
			ProjectModel::ptr       m_model;
			ModelTest::ptr          m_test;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
